<?php
	include_once "dataservice.php";
	include_once "thuvienham.php";
	
	class tinchinh_db
	{
		public function Them($MaBaiViet)
		{
			$sql = "INSERT INTO `tbl_tinchinh`(`MaBaiViet`, `ThoiGianChon`) VALUES ('$MaBaiViet', now())";
			
			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}
		
		public function Xoa($MaBaiViet)
		{
			$sql = "DELETE FROM `tbl_tinchinh` WHERE `MaBaiViet` = '$MaBaiViet'";
			
			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}
		
		public function LayDanhSach()
		{
			$sql = "SELECT * FROM `tbl_tinchinh` WHERE 1 ORDER BY  `ThoiGianChon` DESC";
			
			$service = new dataservice();
			return $service->ExecuteQuery($sql);
		}
		public function LayDanhSachPhanTrang($Start, $Limit)
		{
			$sql = "SELECT * FROM `tbl_tinchinh` WHERE 1 ORDER BY  `ThoiGianChon` DESC LIMIT $Start, $Limit";
			
			$service = new dataservice();
			return $service->ExecuteQuery($sql);
		}
		public function TonTai($MaBaiViet)
		{
			$sql = "SELECT COUNT(*) FROM `tbl_tinchinh` WHERE `MaBaiViet` = '$MaBaiViet'";
			
			$service = new dataservice();
			return ($service->ExecuteScalar($sql) > 0) ? 1 : 0;
		}
	}
?>